<!DOCTYPE html>
<html>

<head>
	<meta charset="UTF-8">
	<title>minglie跨域测试</title>
	<script src="https://minglie.gitee.io/mingpage/static/public/jquery/1.11.3/jquery-1.11.3.js"></script>

	<style>
		button {
			width: 500px;
			height: 30px;
			margin-top: 10px;
		}
	</style>

</head>



<body>
	<button id="btn1">get1</button>
	<button id="btn2">postJson</button>
	<button id="btn3">getCookie</button>
	<button id="btn4">getHeader</button>

	<script>



		let baseUrl = "http://server.com"

		//let baseUrl="http://localhost:8888"


		btn1.onclick = function get1() {
			$.getJSON(`${baseUrl}/get1`).then(function (result) {
				console.log(result);
				btn1.innerHTML = JSON.stringify(result)
			});
		}


		btn2.onclick = () => $.ajax({
			type: "post",
			url: `${baseUrl}/postJson`,
			xhrFields: { withCredentials: true },
			contentType: "application/json;charset=utf-8",
			data: JSON.stringify({ name: "ming" }),
			success: function (json) {
				result = json;
			}
		});




		btn3.onclick = () => $.ajax({
			type: "get",
			url: `${baseUrl}/getCookie`,
			xhrFields: {
				withCredentials: true
			},
			crossDomain: true,
			success: function (json) {
				result = json;
			}
		});



		btn4.onclick = () => $.ajax({
			type: "get",
			url: `${baseUrl}/getHeader`,
			headers: {
				"x-header1": "ming"
			},
			success: function (json) {
				result = json;
			}
		});



	</script>

</body>

</html>